<template>
  <Select v-model="currentValue" @input="handleInput" filterable clearable>
    <Option v-for="item in data" :value="item.id" :key="item.id">{{ item.name }}</Option>
  </Select>
</template>
<script>
  import {getMaterialSel} from '@/api/selectComponents'
  export default {
    name: 'materialSelect',
    components: {
    },
    data () {
      return {
        currentValue: this.value,
        data: []
      };//
    },
    mounted () {
      this.loadData();
    },
    props: ['value'],
    watch: {
      value(val){
        this.$nextTick(() => this.currentValue = val)
      }
    },
    methods: {
      handleInput() {
        this.$emit('input', this.currentValue?this.currentValue:"");
      },
      loadData() {
        getMaterialSel().then(res => {
          if (res.data.code == 200) {
            this.data =res.data.data.data;
          }
        });
      }
    }
  };
</script>
